package designPattern.command.macroCommand
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import org.osmf.events.TimeEvent;

	public class Invoker implements IInvoker
	{
		private var command:ICommand;
		private var timer:Timer;
		public function Invoker()
		{
		}
		
		public function setComand(c:ICommand):void
		{
			command = c;
		}
		
		public function startTimer():void
		{
			timer = new Timer(2000, 3);
			timer.addEventListener(TimerEvent.TIMER, timerHandler);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, removeTimerHandler);
			timer.start();
		}
		
		private function timerHandler(evt:TimerEvent):void
		{
			command.execute();
		}
		
		private function removeTimerHandler(evt:TimerEvent):void
		{
			trace("over");
			timer.removeEventListener(TimerEvent.TIMER, timerHandler);
			timer.removeEventListener(TimerEvent.TIMER_COMPLETE, removeTimerHandler);
		}
	}
}